<?
include_once("/var/www/html/new/com.inc.php");// 公用头部
include_once('/var/www/html/new/d/shops/nav.cfg.php');
//include_once("/var/www/html/new/d/common/yd.le.je");//连接云顶的数据库
//$ydle=new yd_go_sql();
//$ydle->connect();

// 通过二级域名找到该域名绑定账户
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$applyAccount   = substr($host, 0, strpos($host, '.12301'));
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis_key      = "shop_{$applyAccount}";
//$redis->delete($redis_key);
// $redis->setex($redis_key, 1800,'');
$shop           = $redis->get($redis_key);

if (!$shop) {
    $sql = "SELECT `fid`,`M_domain`, `M_name`, `M_logo1`, `M_logo2`, `M_banner`,`M_banner_url`, `M_navi`, `M_qq`, `M_tel`, `M_host`,`M_addr` FROM pft_member_domain_info WHERE M_domain='{$applyAccount}' or M_account_domain='{$applyAccount}' LIMIT 1";
    $GLOBALS['le']->query($sql);
    $shop = $GLOBALS['le']->fetch_assoc();
    if ($shop) {
        $redis->set($redis_key, serialize($shop));
    }else{
		// 没配置二级域名如果是账号访问则生成
		if(is_numeric($applyAccount)){
			$sql="select id from pft_member where account='{$applyAccount}' limit 1";
			$GLOBALS['le']->query($sql);
			$GLOBALS['le']->fetch_assoc();
			if(($sid=$GLOBALS['le']->f('id'))){// 存在该账号
				$shop = array(
					'fid'=>$sid,
					'M_account_domain'=>$applyAccount,
					'M_domain'=>$applyAccount,
					'M_logo1'=>'http://www.12301.cc/shops/images/default/index_logo.png',
					'M_logo2'=>'http://www.12301.cc/shops/images/default/index_logo.png',
					'M_banner'=>'http://www.12301.cc/shops/images/default/login_banner_b.jpg',
					'M_tel'=>'400-99-22301',
					'M_addr'=>'联系地址:福建省福州市鼓楼区西二环218号伯爵大酒店6楼',
				);
				$sql="insert into `pft_member_domain_info` set fid=$sid,M_account_domain='$applyAccount',M_domain='$applyAccount',M_logo1='{$shop['M_logo1']}',M_logo2='{$shop['M_logo2']}',M_banner='{$shop['M_banner']}',M_tel='{$shop['M_tel']}',M_addr='{$shop['M_addr']}',createtime=now()";
				$GLOBALS['le']->query($sql);
			}	
		}
	}
}
else {
    $shop = unserialize($shop);
}
if(!isset($_SESSION['domain_mid'])){
    $_SESSION['domain_mid'] = $shop['fid'];
}
define('APPLY_DID', $_SESSION['domain_mid']);

if(!APPLY_DID)exit('非法访问');

$script = substr($_SERVER['SCRIPT_URL'],(strrpos($_SERVER['SCRIPT_URL'],'/')+1));
if(in_array($script,$login) && !$_SESSION['memberID']){// 必须登录，没有登录
    echo '<script>alert("您未登录，请先登录");</script>';
    echo '<script>window.location.href="home.html"</script>';
    exit;
}
$memberID = $_SESSION['memberID'];
$cartCount = 0;// 初始购物车数量
$loginState = 0;// 初始登录标志（未登录）
if($memberID){
    $str = "select count(*) as c from uu_shoppingcart where fid=$memberID and access='{$_SERVER['HTTP_HOST']}'";
    $GLOBALS['le']->query($str);
    $row = $GLOBALS['le']->fetch_assoc();
    $cartCount = $row['c'];
    $cartCount = ($cartCount=="") ? 0:$cartCount;
    $loginState = 1 ; //登录
    // echo $cartCount;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>桂林旅游公共营销平台</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="http://www.12301.cc/css/new_login_gui.css" /> 
<script language="javascript" type="text/javascript" src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="http://www.12301.cc/js/md5.js"></script>
<script type="text/javascript" src="http://www.12301.cc/js/dlogin_n.js"></script>
<script type="text/javascript" src="http://www.12301.cc/js/new_login_new.js"></script>
	<link rel="stylesheet" href="http://www.12301.cc/shops/css/base.css"/>
	<link rel="stylesheet" href="http://www.12301.cc/shops/css/global.css"/>
<style>
.listUl{ position:relative}
.listUl .liCon{ height:32px; overflow:hidden;line-height:32px;}   
.listUl .statusTxt{ height:200px; line-height:200px; text-align:center}
.listUl .title{display:block;}
.listUl .t{font-size:12px;} 
.conWrap {
width: 100%;
height: 300px;
overflow: hidden;
margin-bottom: 10px;
}
.at{float:right;}
</style>
</head>
<body> 
	<div id="mask"></div>
    <!--头部-->
    <div class="header">
        <div class="top">
            <ul class="top_right">
                <li><a href="#" id="setHome">设为首页</a><span>|</span></li>
                <li><a href="#" id="addFav">加入收藏</a><span>&nbsp;</span></li>
            </ul>
        </div>
        <div class="head">
            <div class="logo">
            	<span><img src="http://www.12301.cc/images/new_login/logo_gui.png" /></a></span>
            </div> 
			<div class="navdl" >
				<ul>
					<li><a href="http://glbzly.12301.cc/new/d/dlogin_gui.html" target="_blank">首&nbsp;&nbsp;&nbsp;页</a></li>
					<li><a href="http://www.12301.cc/u/cpfw_gui.html" target="_blank">产品服务</a></li>  
					<li><a href="http://www.12301.cc/u/index_guilin.html" target="_blank">客户案例</a></li>
					<li><a href="http://www.12301.cc/u/yycj_gui.html" target="_blank">应用场景</a></li>
					<!-- <li><a href="http://www.12301.cc/about_ab.html" target="_blank">关于我们</a></li>  -->
					<li class="tmail"><a href="http://gllygf.alitrip.com/" target="_blank">天猫店铺</a></li> 
				</ul> 
		</div>
        </div>
    </div>
